function socks(r, t) {
	if (r.length < 10) {
		return;
	}
	var sz = cover(true);
	makesocks(sz, r, t);
	loading(true);
	sizesock();
	return false;
}
function nosocks() {
	loading(false);
	$('socksframe').src = '';
	$('socksclose').style.display = 'none';
	$('socksframe').style.display = 'none';
	$('socksmain').style.display = 'none';
	cover(false);
}
function cover(b) {
	var d = $('sockscover');
	if (!d) {
		d = document.createElement('div');
		d.id = 'sockscover';
		document.body.appendChild(d);
		_addevent(d, 'click', nosocks);
	}

	var ob = document.getElementsByTagName('object');
	var vs = (b) ? 'hidden' : 'visible';
	for (var i = 0; i < ob.length; i++) {
		ob[i].style.visibility = vs;
	}

	if (!b) {
		d.style.display = 'none';
		return;
	}

	if (window.innerHeight) {
		var dx = window.innerWidth;
		var dy = window.innerHeight;
	}
	else if (document.documentElement) {
		var dx = document.documentElement.clientWidth.toString();
		var dy = document.documentElement.clientHeight.toString();
	}
	else {
		var dx = document.body.clientWidth.toString();
		var dy = document.body.clientHeight.toString();
	}

	d.style.width = dx + 'px';
	d.style.height = $('gwrapper').offsetHeight + 'px';
	d.style.display = 'block';

	return [dx, dy];
}
function makesocks(s, r, t) {
	var d = $('socksmain');
	if (!d) {

		d = document.createElement('div');
		d.id = 'socksmain';

		var cls = document.createElement('div');
		cls.id = 'socksclose';
		cls.style.display = 'none';
		d.appendChild(cls);

		var clb = document.createElement('div');
		clb.id = 'socksclosebtn';
		//clb.style.display = 'none';
		cls.appendChild(clb);
		_addevent(clb, 'click', nosocks);


		var fvt = document.createElement('div');
		fvt.id = 'socksfavtxt';
		cls.appendChild(fvt);
		_addevent(fvt, 'click', favsocks);

		var cnf = document.createElement('iframe');
		cnf.id = 'socksframe';
		cnf.frameBorder = '0';
		cnf.style.display = 'none';
		d.appendChild(cnf);

		var bbr = document.createElement('div');
		bbr.id = 'socksbottombar';
		bbr.style.display = 'none';

		var btx = document.createElement('input');
		btx.type = 'text';
		btx.id = 'socksbottomtxt';
		btx.readOnly = true;
		bbr.appendChild(btx);

		d.appendChild(bbr);

		document.body.appendChild(d);
	}

	var doc = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement : document.body;

	d.style.left = (s[0] / 2 - 190).toString() + 'px';
	d.style.top = ((s[1] / 2 - 160) + doc.scrollTop).toString() + 'px';
	d.style.width = '380px';
	d.style.height = '320px';

	$('socksclose').style.display = 'none';
	$('socksclose').className = '';
	$('socksfavtxt').innerHTML = '';
	$('socksclosebtn').innerHTML = 'Close';
	$('socksframe').src = '';
	$('socksframe').style.display = 'none';
	$('socksbottombar').style.display = 'none';

	if (!t) {
		$('socksbottomtxt').value = r;
		$('socksbottomtxt').setAttribute('t', r);
	}
	else {
		$('socksbottomtxt').value = t + ' - ' + r;
		$('socksbottomtxt').setAttribute('t', t);
	}

	d.setAttribute('dx', s[0]);
	d.setAttribute('dy', s[1]);
	d.setAttribute('res', r);

	d.style.display = 'block';
}
function sizesock() {
	var d = $('socksmain');

	var wx = d.getAttribute('dx');
	var wy = d.getAttribute('dy');

	var dx = wx - 80;
	var dy = wy - 80;

	var cx = d.offsetWidth;
	var cy = d.offsetHeight;

	if (dx - cx > 20) {
		cx += 20;
		d.style.left = (wx / 2 - cx / 2).toString() + 'px';
		d.style.width = cx.toString() + 'px';
		return window.setTimeout('sizesock()', 10);
	}
	d.style.left = (wx / 2 - dx / 2).toString() + 'px';
	d.style.width = dx.toString() + 'px';

	var doc = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement : document.body;
	
	if (dy - cy > 20) {
		cy += 60;
		d.style.top = ((wy / 2 - cy / 2) + doc.scrollTop).toString() + 'px';
		d.style.height = cy.toString() + 'px';
		return window.setTimeout('sizesock()', 10);
	}
	d.style.top = ((wy / 2 - dy / 2) + doc.scrollTop).toString() + 'px';
	d.style.height = dy.toString() + 'px';

	loading(false);
	var f = $('socksframe');
	var c = $('socksclose');
	c .style.display = 'block';

	$('socksbottombar').style.display = 'block';

	//$('socksclosebtn').style.display = 'none';
	c.className = 'waiting';
	f.style.width = dx.toString() + 'px';
	f.style.height = (dy - 50).toString() + 'px';
	f.style.display = 'block';
	f.src = d.getAttribute('res');
	_addevent(f, 'load', onsocksurl);
}
function onsocksurl() {
	if (isIE) {
		$('socksclose').className = 'favorites';
		$('socksfavtxt').innerHTML = 'Add to favorites';
	}
	else {
		$('socksclose').className = '';
		$('socksfavtxt').innerHTML = '';
	}
	//$('socksclosebtn').innerHTML = 'Close';
	//$('socksclosebtn').style.display = '';
}
function loading(b) {
	$('socksmain').className = (b) ? 'socksloading' : '';
}
var $ = function (s) {
	return document.getElementById(s);
}
function favsocks() {
	var u = $('socksframe').src;
	var t = $('socksbottomtxt').getAttribute('t');
	try {
		window.external.AddFavorite(u, t);
	}
	catch (e) {}
}